package io.cici.cc.mybatis.lite.reflection;

import io.cici.cc.mybatis.lite.util.MapUtil;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;


/**
 * @author huihui
 */
public class ReflectorFactoryImpl implements ReflectorFactory {
    private final ConcurrentMap<Class<?>, Reflector> map = new ConcurrentHashMap<>();
    private final boolean classCacheEnabled = true;

    public ReflectorFactoryImpl() {
    }


    @Override
    public Reflector getReflector(Class<?> type) {
        if (classCacheEnabled) {
            return MapUtil.computeIfAbsent(map, type, Reflector::new);
        }
        return new Reflector(type);
    }

}
